//
//  ZDBTabBarController.swift
//  XinLangMicroblog
//
//  Created by MackBook on 16/9/22.
//  Copyright © 2016年 zx540006260. All rights reserved.
//

import UIKit

class ZDBTabBarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()

//MARK:通过KVC的方式将自定义的tabbar设置上.它是只读的属性,不能直接赋值.self.tabbar = ZDBMainTabBar ()
        
        let tabBar = ZDBMainTabBar ()
       
        //实现闭包:按钮的点击事件
        
        tabBar.composeClosure = { [weak self] in
        
            print("撰写自定义+号按钮的点击方法",self)
            print("---------😁我是华丽的调试线😁---------")

        
        }
        
        self.setValue(tabBar, forKey: "tabBar")
        
        addChildViewControolers ()
        
    }
    
    //MARK:添加自控制器
    
  private  func addChildViewControolers (){
        
        addChildViewControoler(viewController: ZDBHomeViewController (), title: "首页", imageName: "tabbar_home")
        addChildViewControoler(viewController: ZDBMessageViewController (), title: "信息", imageName: "tabbar_message_center")
        addChildViewControoler(viewController: ZDBDiscoverViewController (), title: "发现", imageName: "tabbar_discover")
        addChildViewControoler(viewController: ZDBProfileViewController (), title: "我的", imageName: "tabbar_profile")
        
    }
    
    //MARK:添加子控制器的封装
    
  private  func addChildViewControoler (viewController:UIViewController,title:String,imageName:String){
        
        viewController.navigationItem.title = title
        
        viewController.tabBarItem.title = title
        
        viewController.tabBarItem.image = UIImage(named: imageName)
        
        viewController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        viewController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName :UIColor.orange], for: .selected)
        
        //IOS 10.0出的API,徽标
        
        viewController.tabBarItem.badgeColor = UIColor.green
        
        viewController.tabBarItem.badgeValue = nil
        
        let navController =  ZDBBaseNavigationController (rootViewController: viewController)
        
        //self.viewControllers = [navController]
        
        addChildViewController(navController)
        
    }
    
    
}
